public class Test {
    public static void main(String[] args) {
        int num=0;
        String s=", , , ,   a, aaaddd";
        for(String str:s.split(" ")){
            if(str.equals(" ")){
                num++;
            }
        }
        System.out.println(num);
    }
    public static int func(String s){
        int count=0;
        for(String str:s.split(" ")){
            count++;
        }
        return count;
    }
    public static void main7(String[] args) {
        String s="Hello, my name is John";
        int ret=func(s);
        System.out.println(ret);
    }
    public static void main6(String[] args) {
        //字符串截取
        String str="  what can I say  ";
        String s=str.trim();
        System.out.println(s);
    }
    public static void main5(String[] args) {
        //字符串拆分
        String name="hello&world man &what";
        for(String str:name.split("&")){
            for(String str2:str.split(" ")){
                System.out.println(str2);
            }
        }
        String str4="190\22222\\9999";
        for(String man:str4.split("\\\\")){
            System.out.println(man);
        }
    }
    public static void main4(String[] args) {
        //数字转字符串
        String s1=String.valueOf(1234);
        System.out.println(s1);
        //字符串转数字
        int i=Integer.parseInt("1234");
        System.out.println(i+1);
        //字符串转数组
        String s2="1234";
        char[]man=s2.toCharArray();
        for(char a:man){
            System.out.println(a);
        }
        //格式化输出
        String s5= String.format("%d-%d-%d",2019,6,6);
        System.out.println(s5);
        String s6="aaa";
        System.out.println(s6.replaceAll("a", "man"));
        System.out.println(s6.replaceFirst("a","man"));

    }
    public static void main3(String[] args) {
        String s1="Abc";
        String s2="abcbbade";
        System.out.println(s1.compareTo(s2));
        System.out.println(s1.compareToIgnoreCase(s2));
        System.out.println(s1.charAt(0));
        System.out.println(s1.indexOf('a'));
        System.out.println(s2.indexOf('e', 4));
        System.out.println(s2.indexOf("bb"));
    }
    public static void main2(String[] args) {
        String s1="hhhh";
        String s2="hhhh";
        String s3=s1;
        System.out.println(s1==s3);
        System.out.println(s2 == s1);
        System.out.println(s2 == s3);
        /*System.out.println();
        System.out.println(s1.equals(s2));
        String s4 = new String("hello");
        String s5 = new String("hello");
        String s6 = new String("Hello");
        System.out.println(s4 == s5); // false
        System.out.println(s4 == s6); // false*/
    }
    public static void main1(String[] args) {
        String name="lebron james";
        System.out.println(name);
        String str=new String("Kobe");
        System.out.println(str);
        char[] str1={'h','e','l','l','o'};
        String s=new String(str1);
        System.out.println(s);
        System.out.println();
    }
}
